<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>jsonp.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">jsonp.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    Implements a cross-domain communication channel. A
 typical web page is prevented by browser security from sending
 request, such as a XMLHttpRequest, to other servers than the ones
 from which it came. The Jsonp class provides a workound, by
 using dynamically generated script tags. Typical usage:.

 var jsonp = new goog.net.Jsonp(new goog.Uri(&amp;#39;<a href="http://my.host.com/servlet&amp;#39;)">http://my.host.com/servlet&amp;#39;)</a>);
 var payload = { &amp;#39;foo&amp;#39;: 1, &amp;#39;bar&amp;#39;: true };
 jsonp.send(payload, function(reply) { alert(reply) });

 This script works in all browsers that are currently supported by
 the Google Maps API, which is IE 6.0+, Firefox 0.8+, Safari 1.2.4+,
 Netscape 7.1+, Mozilla 1.4+, Opera 8.02+.
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_net_jsonp.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/closure/goog/net/jsonp.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">net/jsonp.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_net_Jsonp.html">
          goog.net.Jsonp</a><br/>
        <div class="class-details">Creates a new cross domain channel that sends data to the specified
host URL. By default, if no reply arrives within 5s, the channel
assumes the call failed to complete successfully.</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.net.Jsonp.addPayloadToUri_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.net.Jsonp.</span><span class="entryName">addPayloadToUri_<span class="args">(<span class="arg">payload</span>,&nbsp;<span class="arg">uri</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="class_goog_Uri.html">goog.Uri</a></span></div>
      </div>


     <div class="entryOverview">
       Returns URL encoded payload. The payload should be a map of name-value
pairs, in the form {&amp;quot;foo&amp;quot;: 1, &amp;quot;bar&amp;quot;: true, ...}.  If the map is empty,
the URI will be unchanged.

<p>The method uses hasOwnProperty() to assure the properties are on the
object, not on its prototype.</p>
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">payload</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
        <div class="entryOverview">A map of value name pairs to be encoded. A value may be specified as an array, in which case a query parameter will be created for each value, e.g.: {&amp;quot;foo&amp;quot;: [1,2]} will encode to &amp;quot;foo=1&amp;amp;foo=2&amp;quot;.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">uri</span>
        : <div class="fullType"><span class="type"><a href="class_goog_Uri.html">goog.Uri</a></span></div>
        <div class="entryOverview">A Uri object onto which the payload key value pairs will be encoded.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="class_goog_Uri.html">goog.Uri</a></span></div>&nbsp;
            A reference to the Uri sent as a parameter.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_net_jsonp.js.source.html#line317">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.net.Jsonp.cleanup_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.net.Jsonp.</span><span class="entryName">cleanup_<span class="args">(<span class="arg">id</span>,&nbsp;<span class="arg">deleteReplyHandler</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Removes the script node and reply handler with the given id.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">id</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The id of the script node to be removed.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">deleteReplyHandler</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
        <div class="entryOverview">If true, delete the reply handler instead of setting it to nullFunction (if we know the callback could never be called again).</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_net_jsonp.js.source.html#line285">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.net.Jsonp.newErrorHandler_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.net.Jsonp.</span><span class="entryName">newErrorHandler_<span class="args">(<span class="arg">id</span>,&nbsp;<span class="arg">payload</span>,&nbsp;<span class="arg">opt_errorCallback</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>
      </div>


     <div class="entryOverview">
       Creates a timeout callback that calls the given timeoutCallback with the
original payload.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">id</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The id of the script node.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">payload</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">The payload that was sent to the server.</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">opt_errorCallback</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type">undefined</span>)</div>
        <div class="entryOverview">The function called on timeout.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>&nbsp;
            A zero argument function that handles callback duties.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_net_jsonp.js.source.html#line235">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.net.Jsonp.newReplyHandler_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.net.Jsonp.</span><span class="entryName">newReplyHandler_<span class="args">(<span class="arg">id</span>,&nbsp;<span class="arg">replyCallback</span>)</span>
        </span>
        &#8658; <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
      </div>


     <div class="entryOverview">
       Creates a reply callback that calls the given replyCallback with data
returned by the server.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">id</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The id of the script node.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">replyCallback</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">The function called on reply.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>&nbsp;
            A reply callback function.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_net_jsonp.js.source.html#line261">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>






      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory net</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="net/jsonp.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
